package org.example.app.controller;

import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.example.system.entity.AttendanceEntity;
import org.example.system.service.AttendanceService;
import org.example.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 考勤控制层
 */
@RestController
@RequestMapping("/app/attendance")
@Slf4j
public class AttendanceController {
    @Autowired
    private AttendanceService attendanceService;

    /**
     * 添加考勤
     * @param attendance
     * @return
     */
    @PostMapping("/add")
    public R add(@RequestBody AttendanceEntity attendance) {
        log.info("---------AttendanceController | add | input : {}", JSON.toJSON(attendance));
        int row = attendanceService.add(attendance);
        if (row <= 0) {
            return R.fail("添加失败");
        }
        return R.ok("添加成功");
    }
}
